package com.example.sources.servlet;

import javassist.*;
import javassist.bytecode.CodeAttribute;
import javassist.bytecode.LocalVariableAttribute;
import javassist.bytecode.MethodInfo;

/**
 * Created by Administrator on 2016/9/21.
 */
public class Client {
    public static void main(String[] args) {
        ClassPool pool = ClassPool.getDefault();

        CtClass cc;
        try {
            cc = pool.get("com.example.myController.RequestController");

            CtMethod cm = cc.getDeclaredMethod("ids");

            MethodInfo info = cm.getMethodInfo();
            Object[][] o =  cm.getParameterAnnotations();

            CodeAttribute codeAttribute = info.getCodeAttribute();

            LocalVariableAttribute attr = (LocalVariableAttribute) codeAttribute.getAttribute(LocalVariableAttribute.tag);

            int pos = Modifier.isStatic(cm.getModifiers()) ? 0 : 1;

            String[] names=new String[cm.getParameterTypes().length];

            for (int i = 0; i < names.length; i++)
            {
                names[i] = attr.variableName(i + pos);

//                System.out.println(o[i][0].annotationType().getName());
                System.out.println(names[i]);
            }

        } catch (NotFoundException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }


    }
}
